﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
namespace project_assess.prj_view
{
    public partial class prjinfo_frm : Office2007Form
    {
        Mfrm mfrm;
        DataBase m_db;
        public prjinfo_frm(Mfrm frm)
        {
            InitializeComponent();
            mfrm = frm;
            m_db = frm.m_db;
            this.Load += new EventHandler(prjinfo_frm_Load);
            //grid.dataGrid.CellMouseEnter += new DataGridViewCellEventHandler(dataGrid_CellMouseEnter);
            grid.dataGrid.CellBeginEdit += new DataGridViewCellCancelEventHandler(dataGrid_CellBeginEdit);
            grid.dataGrid.CellEndEdit += new DataGridViewCellEventHandler(dataGrid_CellEndEdit);
        
        }
        object oldvalue = null;
        void dataGrid_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
           
            //开始编辑
            if (e.ColumnIndex == 0)
            {
                MessageBox.Show("项目编号无法修改!");
                e.Cancel = true;
            }
            else
            {
                oldvalue = grid.dataGrid.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
            }
        }

        void dataGrid_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            string value =
                grid.dataGrid.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
            Type t =
            grid.dataGrid.Rows[e.RowIndex].Cells[e.ColumnIndex].ValueType;
            value = (t == typeof(string)) ? ("'" + value + "'") : value;
            string columnText =
                grid.dataGrid.Columns[e.ColumnIndex].HeaderText;
            string prjid = grid.dataGrid.Rows[e.RowIndex].Cells[0].Value.ToString();



            if (columnText == "项目经理")//更换项目经理
            {
                
            }
            string sql = string.Format("Update [projects] set [{0}]={1} where [项目编号]='{2}'"
                , columnText, value.ToString(), prjid);
            m_db.ExecuteSQL(sql);
        }

     

        void prjinfo_frm_Load(object sender, EventArgs e)
        {
            load_inf();
        }

        void dataGrid_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
        {
            int rowindex = e.RowIndex;
            this.superTooltip1.SetSuperTooltip(grid.dataGrid, 
        new SuperTooltipInfo("nmb", "", "cnm", null, null, eTooltipColor.System));
        }

        void load_inf()
        {
            string sql = "select [项目编号],[项目名称],[项目经理],[合同额],[地址],[监测类型]" +
                ",[采购厂商],[班组长],[次数],Round([材料埋设],1) as [材料埋设]," +
                "Round([工作量],1) as [工作量] from [projects]";
            DataTable dt = m_db.GetDataSet(sql).Tables[0];
            grid.set_data(dt);
        }
    }
}
